package br.com.conhecimento.core.data;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import br.com.conhecimento.core.model.GestaoTipoUsuario;

@Repository
@Transactional
public class GestaoTipoUsuarioDaoImpl extends GenericDaoImpl<GestaoTipoUsuario, Integer> implements GestaoTipoUsuarioDao {

	@Autowired
	@Override
	public void init(SessionFactory sessionFactory) {
		this.setSessionFactory(sessionFactory);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<GestaoTipoUsuario> getTipoUsuario(Integer idTipoUsuario, String descricao) {
		Criteria crit = getSession().createCriteria(GestaoTipoUsuario.class);
		
		if(idTipoUsuario != null) {
			crit.add(Restrictions.eq("id", idTipoUsuario));
		}
		
		if(descricao != null) {
			crit.add(Restrictions.ilike("descricao", "%"+descricao+"%"));
		}
		
		crit.add(Restrictions.eq("ativo", true));
		
		
		return crit.list();
	}

}
